<?php

class MApnsAction extends CommonAction{
public function index() {
$map = $this->_search ();
if (method_exists ( $this,'_filter')) {
$this->_filter ( $map );
}
$name=$this->getActionName();
$model = M ('ApnsMessages');
if (!empty ( $model )) {
$this->_list ( $model,$map );
}
$this->display ();
return;
}
public function add()
{
$this->display();
}
public function edit() {
$id = intval($_REQUEST ['id']);
$condition['id'] = $id;
$vo = M('ApnsMessages')->where($condition)->find();
$this->assign ( 'vo',$vo );
$this->display ();
}
public function insert() {
B('FilterString');
$ajax = intval($_REQUEST['ajax']);
$data = M('ApnsMessages')->create ();
$this->assign('jumpUrl',u('MApns/add'));
if(!check_empty($data['content']))
{
$this->error(L('CONTENT_EMPTY_TIP'));
}
if($data['send_time']=='')
$data['send_time'] = get_gmtime();
$data['send_time'] = to_timespan($data['send_time']);
$list=M('ApnsMessages')->add($data);
if (false !== $list) {
save_log($log_info.L('INSERT_SUCCESS'),1);
$this->success(L('INSERT_SUCCESS'));
}else {
save_log($log_info.L('INSERT_FAILED'),0);
$this->error(L('INSERT_FAILED'));
}
}
public function update() {
B('FilterString');
$data = M('ApnsMessages')->create ();
$log_info = $data['id'];
$this->assign('jumpUrl',u('MApns/edit',array('id'=>$data['id'])));
if(!check_empty($data['content']))
{
$this->error(L('CONTENT_EMPTY_TIP'));
}
if($data['send_time']=='')
$data['send_time'] = get_gmtime();
$data['send_time'] = to_timespan($data['send_time']);
if(intval($_REQUEST['resend'])==1)
$data['status'] = 0;
$list=M('ApnsMessages')->save ($data);
if (false !== $list) {
save_log($log_info.L('UPDATE_SUCCESS'),1);
$this->success(L('UPDATE_SUCCESS'));
}else {
save_log($log_info.L('UPDATE_FAILED'),0);
$this->error(L('UPDATE_FAILED'),0,$log_info.L('UPDATE_FAILED'));
}
}
public function foreverdelete() {
$ajax = intval($_REQUEST['ajax']);
$id = $_REQUEST ['id'];
if (isset ( $id )) {
$condition = array ('id'=>array ('in',explode ( ',',$id ) ) );
$rel_data = M('ApnsMessages')->where($condition)->findAll();
foreach($rel_data as $data)
{
$info[] = $data['id'];
}
if($info) $info = implode(',',$info);
$list = M('ApnsMessages')->where ( $condition )->delete();
if ($list!==false) {
M('ApnsLogs')->where( array ('message_id'=>array ('in',explode ( ',',$id ) ) ))->delete();
save_log($info.l('FOREVER_DELETE_SUCCESS'),1);
$this->success (l('FOREVER_DELETE_SUCCESS'),$ajax);
}else {
save_log($info.l('FOREVER_DELETE_FAILED'),0);
$this->error (l('FOREVER_DELETE_FAILED'),$ajax);
}
}else {
$this->error (l('INVALID_OPERATION'),$ajax);
}
}
public function logs() {
if(intval($_REQUEST['message_id'])>0)
$map['message_id'] = intval($_REQUEST['message_id']);
$model = M ('ApnsLogs');
if (!empty ( $model )) {
if (isset ( $_REQUEST ['_order'] )) {
$order = $_REQUEST ['_order'];
}else {
$order = !empty ( $sortBy ) ?$sortBy : $model->getPk ();
}
if (isset ( $_REQUEST ['_sort'] )) {
$sort = $_REQUEST ['_sort'] ?'asc': 'desc';
}else {
$sort = $asc ?'asc': 'desc';
}
$count = $model->where ( $map )->count ();
if ($count >0) {
if (!empty ( $_REQUEST ['listRows'] )) {
$listRows = $_REQUEST ['listRows'];
}else {
$listRows = '';
}
$p = new Page ( $count,$listRows );
$voList = $model->where($map)->order( '`'.$order .'` '.$sort)->limit($p->firstRow .','.$p->listRows)->field('*,pid as id')->findAll ( );
foreach ( $map as $key =>$val ) {
if (!is_array ( $val )) {
$p->parameter .= "$key=".urlencode ( $val ) .'&';
}
}
$page = $p->show ();
$sortImg = $sort;
$sortAlt = $sort == 'desc'?l('ASC_SORT') : l('DESC_SORT');
$sort = $sort == 'desc'?1 : 0;
$this->assign ( 'list',$voList );
$this->assign ( 'sort',$sort );
$this->assign ( 'order',$order );
$this->assign ( 'sortImg',$sortImg );
$this->assign ( 'sortType',$sortAlt );
$this->assign ( 'page',$page );
$this->assign ( 'nowPage',$p->nowPage);
}
}
$this->display ();
return;
}
}
?>